#include "App_Fingerprint.h"
// 语音服务
#include "Inf_WTN6170.h"
#include "Inf_BDR6120.h"

/**
 * @brief 指纹任务
 *
 */
void App_Fingerprint_Task(void)
{
    // 接收任务通知值
    uint32_t action = 0;
    // 接收任务通知
    xTaskNotifyWait(UINT32_MAX, UINT32_MAX, &action, 0);
    // 注册
    if (action == 1)
    {
        gpio_intr_disable(TOUCH_INT);
        sayWithoutInt();
        sayPlaceFinger();
        vTaskDelay(3000); // 为了让用户能够放置手指

        // 查询id
        uint16_t id = Inf_FPM383_FindId();
        MY_LOGE("指纹任务 -- id:%d", id);
        // 注册
        // 录入指纹
        Com_Status com_status = Inf_FPM383_RegFinger(id);
        // 判断录入指纹是否成功
        if (com_status == Com_OK)
        {
            sayFingerprintAddSucc();
        }
        else
        {
            sayFingerprintAddFail();
        }
        Inf_FPM383_Sleep();
        return;
    }
    // 删除
    if (action == 2)
    {
        gpio_intr_disable(TOUCH_INT);
        sayWithoutInt();
        sayPlaceFinger();
        vTaskDelay(3000); // 为了让用户能够放置手指
        // 获取当前指纹id
        int16_t id = Inf_FPM383_Current_Id();
        // 获取到数据,进行删除
        MY_LOGE("当前指纹id-- %d", id);
        if (id == -1)
        {
            sayDelFail();
            return;
        }

        Com_Status com_status = Inf_FPM383_DelFinger(id);
        MY_LOGE("当前指纹Com_Status-- %d", com_status);
        if (com_status == Com_OK)
        {
            sayDelSucc();
        }
        else
        {
            sayDelFail();
        }
        Inf_FPM383_Sleep();
        return;
    }
    // 验证
    if (action == 0)
    {
        if (is_has_finger == 1)
        {
            MY_LOGE("验证 is_has_finger--1");

            Com_Status status = Inf_FPM383_CheckFinger();
            if (status == Com_OK)
            {
                sayWithoutInt();
                sayVerifySucc();
                sayWithoutInt();
                sayDoorOpen();
                Inf_BDR6120_OpenLock();
            }
            else
            {
                sayWithoutInt();
                sayVerifyFail();
                sayWithoutInt();
                sayRetry();
            }
            vTaskDelay(3000);
            //  进入休眠模式
            Inf_FPM383_Sleep();
            is_has_finger = 0;
        }
        return;
    }
}
